namespace Microsoft.ServiceModel.Samples.Discovery.Protocol
{
    using System;
    using System.Xml;
    using System.ServiceModel;
    using System.Xml.Serialization;
    using System.Collections.Generic;
    
    
    [XmlType(Namespace = ProtocolStrings.Namespace)]
    [XmlRoot(ProtocolStrings.ResolveElement,
        Namespace = ProtocolStrings.Namespace)]
    public class Resolve
    {
        public static Resolve FromEndpointAddress(EndpointAddress address)
        {
            if (address == null)
                throw new ArgumentNullException("address");

            Resolve resolve = new Resolve();
            resolve.EndpointAddress = address;

            return resolve;
        }

        EndpointAddressAugust2004 endpointReferenceField;
        XmlElement[] anyField;
        XmlAttribute[] anyAttrField;

        [XmlElement(
        ElementName = ProtocolStrings.EprElement,
        Namespace = ProtocolStrings.WsaNamespace)]
        public EndpointAddressAugust2004 EndpointAddressAugust2004
        {
            get
            {
                return this.endpointReferenceField;
            }

            set
            {
                this.endpointReferenceField = value;
            }
        }
            
        [XmlAnyElement]
        public XmlElement[] AnyElements
        {
            get
            {
                return this.anyField;
            }
            set
            {
                this.anyField = value;
            }
        }

        /// <remarks/>
        [XmlAnyAttributeAttribute()]
        public XmlAttribute[] AnyAttributes
        {
            get
            {
                return this.anyAttrField;
            }
            set
            {
                this.anyAttrField = value;
            }
        }

        [XmlIgnore]
        public EndpointAddress EndpointAddress
        {
            get
            {
                if (this.EndpointAddressAugust2004 != null)
                    return this.EndpointAddressAugust2004.ToEndpointAddress();
                else
                    return null;
            }

            set
            {
                if (value != null)
                {
                    this.EndpointAddressAugust2004 =
                        EndpointAddressAugust2004.FromEndpointAddress(value);
                }
                else
                    this.EndpointAddressAugust2004 = null;
            }
        }

        public bool IsValid()
        {
            return (this.EndpointAddress != null);
        }
    }
}
